#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>

/*
	mynode@0x12345678{
		compatible = "hqyj, mynode";
		astring = "i am ok";
		uint = <0x11223344>;
		binint = [00 0c 29 78 f8 be];
		mixed = "dc2022", <0x8899aabb>, [01 02 03 04];
	};
*/

MODULE_LICENSE("GPL");

static struct device_node* node;

static int __init dt_demo_init(void)
{
    int returnLength;
    struct property* findProperties;

    // node = of_find_node_by_path("/mynode@0x12345678");
    // if(!node) printk("of_find_node_by_path(\"/mynode@0x12345678\") is not find node");
    // node = of_find_node_by_name(NULL, "mynode");
    // if(!node) printk("of_find_node_by_name(NULL, \"mynode\") is not find node");
    node = of_find_compatible_node(NULL,NULL,"hqyj,mynode");
    if(!node)
    {
        printk("of_find_compatible_node(NULL,NULL,:\"hqyj,mynide\") is not find node");
        printk("not find spec node!\n");
        return -ENODEV;
    }

    printk("node name = %s, full name = %s\n", node->name, node->full_name);

    printk("=================properties===================\n");
    findProperties = node->properties;
    for(; findProperties; findProperties = findProperties->next)
    {
        printk("name=%s, length=%d\n", findProperties->name, findProperties->length);
    }

    findProperties = of_find_property(node,"binint",&returnLength);
    if(findProperties)
    {
        char* tmpValue = (char*)findProperties->value;
        printk("name=%s, length=%d, value=[%#2X %#2X %#2X %#2X %#2X %#2X]",
        findProperties->name,returnLength,
        *(tmpValue),*(tmpValue+1),*(tmpValue+2),*(tmpValue+3),*(tmpValue+4),*(tmpValue+5));
    }
        
    return 0;
}

static void __exit dt_demo_exit(void)
{
    of_node_put(node);
}

module_init(dt_demo_init);
module_exit(dt_demo_exit);